package controlador;

import vista.loginBean;
import daoBeans.conexionMySql;
import daoBeans.daoEmpresa;
import daoBeans.daoUsuario;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import modelo.Empresa;
import modelo.Usuario;

@ManagedBean(name = "galleriaBean")
@RequestScoped
public class GalleriaBean {

    private conexionMySql sql;
    private Statement st;
    private Connection mysql;
    private List<String> images;

    @PostConstruct
    public void init() {
        images = new ArrayList<String>();

        for (int i = 1; i < 8; i++) {
            images.add("gallery" + i + ".jpg");
        }

        
        sql = new conexionMySql();
        mysql = sql.comenzarDb();

        try {
            st = mysql.createStatement();
            st.executeUpdate("CREATE TABLE Empresa ("
                    + "Nombre VARCHAR(20),"
                    + "NIT VARCHAR(20),"
                    + "Tipo ENUM('Distribuidor', 'Subdistribuidor', 'Punto de Venta', 'Canal'), "
                    + "Padre VARCHAR(20), "
                    + "PRIMARY KEY(NIT), "
                    + "UNIQUE KEY(Nombre), "
                    + "UNIQUE KEY(NIT)"
                    + ");");


            st.executeUpdate("create table Usuario ("
                    + "Nombre VARCHAR(20) NOT NULL, "
                    + "ID VARCHAR(10), "
                    + "Rol ENUM('adminDist', 'adminSubDist', 'adminCan', 'adminPV', 'search', 'other','adminTI'),"
                    + "Empresa VARCHAR(20), "
                    + "Username VARCHAR(20), "
                    + "Password VARCHAR(20), "
                    + "PRIMARY KEY (ID), "
                    + "FOREIGN KEY (Empresa) REFERENCES Empresa(NIT), "
                    + "UNIQUE KEY(Username), "
                    + "UNIQUE KEY(Password) "
                    + ");");

            st.executeUpdate("INSERT INTO Empresa "
                    + "VALUES ('p1', '555444333222', 'Distribuidor', 'admin');");

            st.executeUpdate("INSERT INTO Empresa "
                    + "VALUES ('p2', '011515141568', 'Subdistribuidor', '555444333222');");

            st.executeUpdate("INSERT INTO Empresa "
                    + "VALUES ('p3', '514444333222', 'Punto de Venta', '011515141568');");

            st.executeUpdate("INSERT INTO Empresa "
                    + "VALUES ('p4', '555654123222', 'Canal', '514444333222');");

            st.executeUpdate("INSERT INTO Usuario "+ "VALUES ('admin', '222555444', 'adminTI', '555444333222', 'admin', 'admin');");

            st.executeUpdate("INSERT INTO Usuario "+ "VALUES ('Gustavo', '221455444', 'adminDist', '555444333222', 'gariosp', 'gariosp');");

            st.executeUpdate("INSERT INTO Usuario "+ "VALUES ('Manuel', '111555444', 'adminSubDist', '011515141568', 'mfcardenasr', 'mfcardenasr');");

            st.executeUpdate("INSERT INTO Usuario "+ "VALUES ('Camilo', '333555444', 'adminCan', '555444333222', 'caarodriguezhe', 'caarodriguezhe');");

            st.executeUpdate("INSERT INTO Usuario "+ "VALUES ('Daniel', '000555444', 'adminPV', '555444333222', 'dfmanriqueg', 'dfmanriqueg');");

            st.executeUpdate("INSERT INTO Usuario "+ "VALUES ('Andres', '555555444', 'other', '555654123222', 'afpenuelav', 'afpenuelav');");

            st.executeUpdate("INSERT INTO Usuario "+ "VALUES ('Pedro', '123555444', 'search', '555444333222', 'search1', 'search1');");

        } catch (SQLException ex) {
            Logger.getLogger(loginBean.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public List<String> getImages() {
        return images;
    }
}